<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
    <title>骨医快线</title>
    <link href="../../../css/mui.plus.css" rel="stylesheet" />
    <link rel="stylesheet" type="text/css" href="../../../css/mui.picker.min.css"/>
    <link rel="stylesheet" type="text/css" href="../../../css/mui.poppicker.css"/>
    <style>
    	.mui-input-row label {
    		width: 65%;
    	}
    	.mui-input-row label ~ input {
    		width: 35%;
    	}
    </style>
</head>
<body>
	<header class="mui-bar mui-bar-nav oe-pri-bar">
	    <a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
	    <h1 class="mui-title">其他信息</h1>
	</header>
	<footer class="mui-bar mui-bar-footer" style="padding: 0;height: 50px;">
        <button type="button" id="btn-commit" class="mui-btn mui-btn-primary mui-btn-block" style="padding:10px 0;">保&nbsp;&nbsp;存</button>
    </footer>
	
    <div class="mui-content oe-helper">
    	<form class="mui-input-group" id="list-input">
            <div class="mui-input-row">
                <label>住院时间(天)</label>
                <input type="text" name="case_other_hospital_stay" placeholder="请填写" style="text-align: right;">
            </div>
            <div class="mui-input-row">
                <label class="oe-label-pick">死亡时间</label>
                <input type="hidden" value="" name="case_other_death_date" id="hid2" />
                <button id="btn-time-death" type="button" class="mui-btn oe-btn-pick" data-options='{"type":"date","beginYear":2010,"endYear":2020}'>请选择</button>
            </div>
            <div class="mui-input-row">
                <label>死亡原因</label>
                <input type="text" name="case_other_death_reason" placeholder="请填写" style="text-align: right;">
            </div>
       </form>
    </div>
    
    <script id="tmp-list-input" type="text/html">
    	{{if data}}
    		<div class="mui-input-row">
                <label>住院时间(天)</label>
                <input type="text" name="case_other_hospital_stay" placeholder="请填写" style="text-align: right;" value="{{data.case_other_hospital_stay}}">
            </div>
            <div class="mui-input-row">
                <label class="oe-label-pick">死亡时间</label>
                <input type="hidden" value="" name="case_other_death_date" id="hid2" />
                <button id="btn-time-death" type="button" class="mui-btn oe-btn-pick" data-options='{"type":"date","beginYear":2010,"endYear":2020}'>{{data.case_other_death_date || 请选择}}</button>
            </div>
            <div class="mui-input-row">
                <label>死亡原因</label>
                <input type="text" name="case_other_death_reason" placeholder="请填写" style="text-align: right;" value="{{data.case_other_death_reason}}">
            </div>
    	{{/if}}
    </script>

    <script src="../../../js/mui.min.js"></script>
    <script src="../../../js/app.js"></script>
    <script src="../../../js/lib/template.js"></script>
    <script src="../../../js/mui.picker.min.js"></script>
    <script src="../../../js/mui.poppicker.js"></script>
    <script>
    	(function($, a){
    		var wv,
    			caseId,
    			html,
    			tmpData,
    			commitData;
    			
//  		var hid1 = document.getElementById("hid1"),
//  			hid2 = document.getElementById("hid2");
    			
    		$('body').on('tap', '#btn-commit', function(){
    			commitData = app.form.getJsonFromForm('list-input');
    			commitData.case_id = caseId;
    			
    			CommitDataById(commitData);
    		});
    		
//  		$('.mui-content').on('tap', '#btn-time-stay', function () {
//				var self = this;
//              var optionsJson = this.getAttribute('data-options') || '{}';
//              var options = JSON.parse(optionsJson);
//              var picker = new $.DtPicker(options);
//              picker.show(function (rs) {
//                  hid1.value = rs.text;
//                  self.textContent = rs.text;
//                  if(self.textContent !== '请选择'){
//                  	self.style.color = '#000';
//                  }
//                  picker.dispose();
//              });
//          });
            
            $('.mui-content').on('tap', '#btn-time-death', function () {
				var self = this,
					hid2 = document.getElementById("hid2");
                var optionsJson = this.getAttribute('data-options') || '{}';
                var options = JSON.parse(optionsJson);
                var picker = new $.DtPicker(options);
                picker.show(function (rs) {
                    hid2.value = rs.text;
                    self.textContent = rs.text;
                    if(self.textContent !== '请选择'){
                    	self.style.color = '#000';
                    }
                    picker.dispose();
                });
            });
    		
    		$.plusReady(function(){
    			wv = plus.webview.currentWebview();
    			caseId = wv.caseId;
    			type = wv.type;
				
				getCaseInfoById(caseId, type);
    		});
    		
    		var getCaseInfoById = function(caseId, type){
    			app.net.get('c_old_man_hip_broke_prj_case/show_by_type', {case_id: caseId, case_type: type}, function(data){
    				if(data && data.code === '100') {
    					tmpData = data;
    					html = template('tmp-list-input', tmpData);
    					document.getElementById("list-input").innerHTML = html;
    				}
    			});
    		}
    		
    		var CommitDataById = function(commitData){
    			app.net.post('c_old_man_hip_broke_prj_case/update', commitData, function(data){
    				if(data && data.code === '100') {
    					$.toast('保存成功');
    					$.back();
    				}else {
    					$.toast('您尚未进行任何修改哦');
    				}
    			});
    		}
    		
    	}(mui, app));
    </script>
</body>
</html>